﻿@{
    ViewBag.Title = "OutstockSporadicIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
    <script type="text/javascript">
        var mainheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 10;
        $(document).ready(function () {
            $("#instockDt").datepicker({ dateFormat: 'yy-mm-dd' });
            $("#endDt").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = mainheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetOutstockSporadicList")',
                colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '领用日期', name: 'LeanDt', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '零星物品ID', name: 'GoodsID', width: 50, sortable: false, hide: true, align: 'left' },
                    { display: '零星物品', name: 'GoodsID', width: 150, sortable: false, hide: false, align: 'left' },
			        { display: '领用食堂', name: 'LeanDept', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '领用数量', name: 'LeanCount', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '操作人', name: 'Operator_ID', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '批号', name: 'OrderNo', width: 80, sortable: false, hide: true, align: 'left' }
				],
                buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItemAdd_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItemEdit_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItemDel_onclick },
                            { separator: true }
                         ],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpOptions: [10, 15,20],
                showcheckbox: true,
                rowbinddata: true
            };
            var instockgrid = $("#OutstockSporadic").flexigrid(option);

            function toolbarItemAdd_onclick(cmd) {
                OpenModelWindow('@Url.Action("AddOutstockSporadic")?id=0',
                                   { width: 750, height: 450, caption: "添加零星物品出库", onclose: refresh });
            }  // end of toolbarItemAdd_onclick

            function toolbarItemEdit_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要修改的零星物品!", { left: 400, top: 2 }, true, 3000);
                    return false;
                }
                var id = items[0][0];
                OpenModelWindow('@Url.Action("AddOutstockSporadic")?id=' + id,
                                   { width: 750, height: 450, caption: "修改零星物品进货明细", onclose: refreshbyclick });
            }  // end of toolbarItemEdit_onclick

            function toolbarItemDel_onclick(cmd) {
                var items = $(instockgrid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的零星物品!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除零星物品吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteSporadic")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });   // end of ajax                    
                }
                if ($("#orderno").val()) {
                    refresh();
                }
                else {
                    refreshbyclick();
                }
                showLoadingMsg("共有" + rowcount.toString() + "个食材被删除!", { left: 400, top: 6 }, true, 3000);
            }  // end of toolbarItemDel_onclick

            $("#btnQueryList").click(function () {
                refreshbyclick();
            });

            function refreshbyclick() {
                var idt = ($("#instockDt").val() == null) ? "" : $("#instockDt").val();
                var iname = ($("#Con_GoodsInfoId").val() == null) ? "" : $("#Con_GoodsInfoId").val();
                var enddt = ($("#endDt").val() == null) ? "" : $("#endDt").val();
                if ($("#Con_GoodsInfoGoodsName").val() == "") {
                    iname = "";
                }
                option.query = "and ((LeanDt >= '" + idt + "') and (LeanDt <='" + enddt + "')) and "
                                  + "((GoodsID = '" + iname + "') or ('" + iname + "'=''))";
                option.newp = 0;
                $("#OutstockSporadic").flexOptions(option).flexReload();
            }
            function refresh() {
                option.query = "and OrderNo = '" + $("#orderno").val() + "'";
                option.newp = 0;
                $("#OutstockSporadic").flexOptions(option).flexReload();
            }
        });
    </script>
}
 <div id="container">
        <div id="mainContent">
            <div id="title" class="title">零星物品列表</div>
            <div id="findDiv">
            @Html.Hidden("orderno")
             <table>
                <tr>
                 <td style="text-align:right; width:80px;">开始日期：</td>
                 <td>@Html.TextBox("instockDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })</td>
                 <td style="text-align:right; width:80px;">结束日期:</td>
                 <td>@Html.TextBox("endDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })</td>
                 <td style="text-align:right; width:100px;">零星物品名称：</td>
                 <td>
			     @Html.Partial("RtnSpoAllGoodsList")
				 </td>
                 <td><a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                 </td>
                </tr>
             </table>
            </div>
            <table id="OutstockSporadic" style="display: none;">
            </table>
        </div>
    </div>


